home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt40s4.arc / PIBTERM.BIG next >
Text File  |  1987-09-08  |  17KB  |  414 lines

  1. {Main module of program PIBTERM.BIG}
  2.  
  3. {.N PT4KERM}
  4. {.N PT4XMOD}
  5. {.N PT4EDIT}
  6. {.N PT4HOST}
  7. {.N PT4USER}
  8. {.N PT4T4010}
  9. {.N PT4SCRI}
  10. {.N PT4DIAL}
  11. {.N PT4UTIL}
  12. {.N PT4INIT}
  13. {.N PT4UTIL}
  14. {.N PT4TERM}
  15. {.N PT4GOSSI}
  16.  
  17. (*$C-,V-,U-,R-,K-*)
  18. PROGRAM PibTerm;
  19.  
  20. (*----------------------------------------------------------------------*)
  21. (*               PibTerm --- Terminal Emulator in Turbo Pascal          *)
  22. (*----------------------------------------------------------------------*)
  23. (*                                                                      *)
  24. (*  Author:   (c) 1985, 1986, 1987 by Philip R. Burns                   *)
  25. (*                                                                      *)
  26. (*  Date:     January, 1987                                             *)
  27. (*  Version:  1.0  (January, 1985)                                      *)
  28. (*            2.0  (July, 1985)                                         *)
  29. (*            3.0  (October, 1985)                                      *)
  30. (*            3.2  (November, 1985)                                     *)
  31. (*            4.0  (September, 1987)                                    *)
  32. (*                                                                      *)
  33. (*  Systems:  For MS-DOS on IBM PCs and close compatibles only.         *)
  34. (*            Note:  I have checked these on under MSDOS 2.x/3.x        *)
  35. (*                   on a variety of IBM PCs and clones.                *)
  36. (*                                                                      *)
  37. (*  Overview: This program provides a comprehensive terminal emulation  *)
  38. (*            and remote communications facility.  PibTerm emulates     *)
  39. (*            several different terminals.                              *)
  40. (*                                                                      *)
  41. (*            PibTerm allows for file transfer facilities using         *)
  42. (*            many different protocols.                                 *)
  43. (*                                                                      *)
  44. (*            The commands and general program use follow that of other *)
  45. (*            popular communications programs like PC-Talk and Qmodem.  *)
  46. (*                                                                      *)
  47. (*            PibTerm also provides a simple host communications        *)
  48. (*            facility like a mini-BBS.                                 *)
  49. (*                                                                      *)
  50. (*----------------------------------------------------------------------*)
  51. (*                                                                      *)
  52. (*                            Restriction                               *)
  53. (*                            -----------                               *)
  54. (*                                                                      *)
  55. (*           You may use this code only for NON COMMERCIAL purposes     *)
  56. (*           unless you explicitly obtain my permission.  I take a dim  *)
  57. (*           view of others making money on my work and those of other  *)
  58. (*           people whose code I've inserted here.                      *)
  59. (*                                                                      *)
  60. (*           Please feel free to add new features.  I wrote this        *)
  61. (*           program to give people a useful and usable basic terminal  *)
  62. (*           facility, and to show how Turbo Pascal can be used for     *)
  63. (*           asynchronous communications, menu display, windowing, and  *)
  64. (*           so on.  I hope that you find this program useful -- and,   *)
  65. (*           if you expand upon it, please upload your extensions so    *)
  66. (*           that all of us can enjoy them!                             *)
  67. (*                                                                      *)
  68. (*----------------------------------------------------------------------*)
  69. (*                                                                      *)
  70. (*           Suggestions for improvements or corrections are welcome.   *)
  71. (*           Please leave messages on Gene Plantz's BBS (312) 882 4145  *)
  72. (*           or Ron Fox's BBS (312) 940 6496.                           *)
  73. (*                                                                      *)
  74. (*----------------------------------------------------------------------*)
  75.  
  76.                                    (* Global const/type/var definitions *)
  77. {$I PIBTDCL1.GLO }
  78. {$I PIBTDCL2.GLO }
  79.                                    (* Turbo extender definitions        *)
  80. {$I BIGTURBO.VAR }
  81.                                    (* Time of day for status line       *)
  82. {$I FASTTIME.MOD }
  83.                                    (* Write to status line              *)
  84. {$I WRITESTA.MOD }
  85.                                    (* Updates status line               *)
  86. {$I UPDATEST.MOD }
  87.                                    (* Read keyboard driver              *)
  88. {$I RDKEYBRD.MOD }
  89.                                    (* Error handler interface           *)
  90. {$I TRAPERRO.MOD }
  91.  
  92. {Includes for exported shells of other modules}
  93.  
  94. {$I LOADMOD.IN1  }
  95. {$I PT4KERM.EXP  }
  96. {$I PT4XMOD.EXP  }
  97. {$I PT4EDIT.EXP  }
  98. {$I PT4HOST.EXP  }
  99. {$I PT4USER.EXP  }
  100. {$I PT4INIT.EXP  }
  101. {$I PT4SETP.EXP  }
  102. {$I PT4UTIL.EXP  }
  103. {$I PT4SCRI.EXP  }
  104. {$I PT4TERM.EXP  }
  105. {$I PT4GOSSI.EXP }
  106. {$I PT4T4010.EXP }
  107.  
  108. {executable code local to this module follows}
  109.  
  110. PROCEDURE Print_Spooled_File;
  111.    FORWARD;
  112.  
  113. PROCEDURE Error_Handler( ErrNo , ErrAddr : INTEGER );
  114.    FORWARD;
  115.  
  116. FUNCTION Color_Screen_Active : BOOLEAN;
  117.    FORWARD;
  118.  
  119. PROCEDURE UnloadAllModules;
  120.    FORWARD;
  121.                                    (* Intercepts Turbo's HALT           *)
  122. {$I PIBHALT.MOD  }
  123.                                    (* Critical error interrupt handler  *)
  124. {$I INT24.MOD    }
  125.                                    (* Convert hex string to decimal #   *)
  126. {$I HEXTODEC.MOD }
  127.                                    (* Convert decimal # to hex string   *)
  128. {$I DECTOHEX.MOD }
  129.                                    (* Convert integer to string         *)
  130. {$I ITOS.MOD     }
  131.                                    (* Multitasker interface routines    *)
  132. {$I PIBMDOS.MOD  }
  133.                                    (* Read character from keyboard      *)
  134. {$I READKBD.MOD  }
  135.                                    (* Get string from DOS environment   *)
  136. {$I GETENVST.MOD  }
  137.                                    (* Do a "press any" question         *)
  138. {$I PRESSANY.MOD }
  139.                                    (* Find minimum/maximum of numbers   *)
  140. {$I MINMAX.MOD   }
  141.                                    (* Duplicate a character into string *)
  142. {$I DUPL.MOD     }
  143.                                    (* Trim blanks from end of string    *)
  144. {$I TRIM.MOD     }
  145.                                    (* Trim blanks from front of string  *)
  146. {$I LTRIM.MOD    }
  147.                                    (* Extract substring of a string     *)
  148. {$I SUBSTR.MOD   }
  149.                                    (* Convert string to uppercase       *)
  150. {$I UPPERCAS.MOD }
  151.                                    (* Copy string to array of char      *)
  152. {$I COPYSTOA.MOD }
  153.                                    (* Read string with control chars    *)
  154. {$I READCTRL.MOD }
  155.                                    (* Write string with control chars   *)
  156. {$I WRITCTRL.MOD }
  157.                                    (* Adjust time for am/pm difference  *)
  158. {$I ADJUSTHR.MOD }
  159.                                    (* Timer interface routines          *)
  160. {$I PIBTIMER.MOD }
  161.                                    (* Asynchronous I/O interface        *)
  162. {$I PIBASYN1.MOD }
  163. {$I PIBASYN2.MOD }
  164. {$I PIBASYN3.MOD }
  165.                                    (* Redefine Int 9 keyboard handler   *)
  166. {$I KBDINTP.MOD  }
  167.                                    (* Open file for append              *)
  168. {$I OPENFORA.MOD }
  169.                                    (* Get maximum available storage     *)
  170. {$I MAXBLOCK.MOD }
  171.                                    (* Update review pointers            *)
  172. {$I UPDATERE.MOD }
  173.                                    (* Write time stamped string to log  *)
  174. {$I WRITELOG.MOD }
  175.                                    (* Screen management routines        *)
  176. {$I PIBSCRN1.MOD }
  177. {$I PIBSCRN2.MOD }
  178. {$I WRITECXY.MOD }
  179. {$I MOVETOXY.MOD }
  180. {$I PIBSCRN3.MOD }
  181.                                    (* Redefine Int 10 video handler     *)
  182. {$I VIDINTP.MOD  }
  183.                                    (* Scroll portion of screen          *)
  184. {$I SCROLL.MOD   }
  185.                                    (* Clear out current window          *)
  186. {$I CLEARWIN.MOD }
  187.                                    (* Pop-up menu routines              *)
  188. {$I PIBMENUS.MOD }
  189.                                    (* MS DOS directory routines         *)
  190. {$I PIBDIR.MOD   }
  191.                                    (* File handle I/O routines          *)
  192. {$I PIBFHIO.MOD  }
  193.                                    (* Send string to modem              *)
  194. {$I SENDMODE.MOD }
  195.                                    (* Print character from spool file   *)
  196. {$I PRINTSPO.MOD }
  197.                                    (* Get yes/no answer                 *)
  198. {$I YESNO.MOD    }
  199.                                    (* Hangup the phone -- Alt_H         *)
  200. {$I HANGUP.MOD   }
  201.                                    (* Generate a menu                   *)
  202. {$I MAKEMENU.MOD }
  203. {$I MAKEMEND.MOD }
  204.                                    (* Get stack pointer                 *)
  205. {$I STACKPOI.MOD }
  206.                                    (* Stuff keyboard buffer             *)
  207. {$I STUFFKBD.MOD }
  208.                                    (* Edit a string                     *)
  209. {$I EDITSTRI.MOD }
  210.                                    (* Read and edit a string            *)
  211. {$I READEDIS.MOD }
  212.                                    (* Read a number                     *)
  213. {$I READNUMB.MOD }
  214.                                    (* Overlay module loader interface   *)
  215. {$I MYLOADO.MOD  }
  216.                                    (* DOS jump interface                *)
  217. {$I DOSJUMP.MOD  }
  218.                                    (* Auto find file name               *)
  219. {$I GETAUTOF.MOD }
  220.                                    (* Display transfer types menu       *)
  221. {$I DISPLYTT.MOD }
  222.                                    (* Get upload protocol -- Alt_S      *)
  223. {$I GETUPLOA.MOD }
  224.                                    (* Get download protocol -- Alt_R    *)
  225. {$I GETDOWNL.MOD }
  226.                                    (* Signal end of transfer            *)
  227. {$I SIGENDTR.MOD }
  228.                                    (* Transfer file through batch file  *)
  229. {$I TRANSBAT.MOD }
  230.                                    (* General file transfer handler     *)
  231. {$I PIBUPDOW.MOD }
  232.                                    (* General upload handler -- Alt_S   *)
  233. {$I PIBUPLOD.MOD }
  234.                                    (* General download handler -- Alt_R *)
  235. {$I PIBDWLOD.MOD }
  236.                                    (* Initialize directories            *)
  237. {$I INITOVLY.MOD }
  238.                                    (* Initialize PibTerm interface      *)
  239. {$I INITTERM.MOD }
  240.                                    (* Finish execution -- Alt_X         *)
  241. {$I FINITERM.MOD }
  242.                                    (* General error handler             *)
  243. {$I ERRORHAN.MOD }
  244.                                    (* Get command line parameters       *)
  245. {$I GETCOMAN.MOD }
  246.                                    (* Define a key                      *)
  247. {$I DEFINEKY.MOD }
  248.  
  249. (*----------------------------------------------------------------------*)
  250.  
  251. PROCEDURE Terminal_Emulations;
  252.  
  253. (* STRUCTURED *) CONST
  254.    PibTerm_Stops : STRING[18] = '*** PibTerm stops.';
  255.  
  256. (*----------------------------------------------------------------------*)
  257.  
  258. PROCEDURE Load_User_Terminal;
  259.  
  260. VAR
  261.    User_Number : INTEGER;
  262.  
  263. BEGIN (* Load_User_Terminal *)
  264.  
  265.    User_Number := SUCC( ORD( Terminal_To_Emulate ) - ORD( User1 ) );
  266.  
  267.    IF ( POS( '.CHN', UpperCase( User_Term_Name[User_Number] ) ) > 0 ) THEN
  268.       BEGIN
  269.          IF MyLoadOverlay( 2, PT4USER, User_Term_Name[User_Number] ) THEN
  270.             BEGIN
  271.                Emulate_User_Terminal;
  272.                UnloadEmulator;
  273.             END
  274.          ELSE
  275.             Terminal_To_Emulate := Saved_Gossip_Term;
  276.       END
  277.    ELSE
  278.       Emulate_General_Terminal;
  279.  
  280. END   (* Load_User_Terminal *);
  281.  
  282. (*----------------------------------------------------------------------*)
  283.  
  284. BEGIN (* Terminal_Emulations *)
  285.                                    (* Load terminal emulation module  *)
  286.  
  287.    IF ( NOT MyLoadOverlay( 1, PT4TERM, 'PT4TERM.CHN' ) ) THEN
  288.       BEGIN
  289.          WRITELN(PibTerm_Stops);
  290.          Halt( 1 );
  291.       END;
  292.  
  293.    REPEAT
  294.  
  295.       CASE Terminal_To_Emulate OF
  296.  
  297.          Ansi         : Emulate_Ansi( FALSE );
  298.  
  299.          VT100        : Emulate_Ansi( TRUE );
  300.  
  301.          VT52,
  302.          ADM3a,
  303.          ADM5,
  304.          TV925,
  305.          Dumb         : Emulate_General_Terminal;
  306.  
  307.          Gossip       : IF MyLoadOverlay( 2, PT4GOSSI, 'PT4GOSSI.CHN' ) THEN
  308.                            BEGIN
  309.                               Emulate_Gossip;
  310.                               UnloadEmulator;
  311.                            END
  312.                         ELSE
  313.                            BEGIN
  314.                               Terminal_To_Emulate := Saved_Gossip_Term;
  315.                               Gossip_Mode_On      := FALSE;
  316.                            END;
  317.  
  318.          HostMode     : BEGIN
  319.                            IF MyLoadOverlay( 1, PT4HOST, 'PT4HOST.CHN' ) THEN
  320.                               BEGIN
  321.                                  Emulate_Host;
  322.                                  IF ( NOT MyLoadOverlay( 1, PT4TERM, 'PT4TERM.CHN' ) ) THEN
  323.                                     BEGIN
  324.                                        WRITELN('*** Can''t load main terminal emulator module.');
  325.                                        WRITELN(PibTerm_Stops);
  326.                                        PibTerm_Done := TRUE;
  327.                                     END;
  328.                               END
  329.                            ELSE
  330.                               BEGIN
  331.                                  Terminal_To_Emulate := Saved_Gossip_Term;
  332.                                  Host_Mode           := FALSE;
  333.                               END;
  334.                         END;
  335.  
  336.          User1..User5 : Load_User_Terminal;
  337.  
  338.          TEK4010      : IF MyLoadOverlay( 2, PT4T4010, 'PT4T4010.CHN' ) THEN
  339.                            BEGIN
  340.                               Emulate_TEK4010;
  341.                               UnloadEmulator;
  342.                            END
  343.                         ELSE
  344.                            Terminal_To_Emulate := Ansi;
  345.  
  346.          ELSE;
  347.  
  348.       END (* CASE *);
  349.  
  350.    UNTIL ( PibTerm_Done );
  351.  
  352. END   (* Terminal_Emulations *);
  353.  
  354. (* ------------------------------------------------------------------------ *)
  355. (*                  PibTerm  --- Main Program                               *)
  356. (* ------------------------------------------------------------------------ *)
  357.  
  358.   {the jump table procedure and data for this module}
  359.   {$I PIBTERM.JMP}
  360.  
  361.   {BIGTURBO support routines}
  362.   {$I farctrl.inc}
  363.   {$I loadmod.in2}
  364.  
  365. BEGIN (* PibTerm  *)
  366.                                    (* Remember top of stack for later *)
  367.    TopOfStack := StackPointer;
  368.                                    (* Get command line parameters     *)
  369.    Get_Command_Line_Parameters;
  370.                                    (* Initialize Turbo Extender       *)
  371.    InitializeBigTurbo;
  372.                                    (* Set dynamic overlay areas.      *)
  373.                                    (* Term module MUST be present.    *)
  374.                                    (* Note:  Only done if EMM loading *)
  375.                                    (*        NOT to be done.          *)
  376.                                    (* Note:  Following test done this *)
  377.                                    (*        way instead of as        *)
  378.                                    (*        simple logical assignment*)
  379.                                    (*        to avoid checking EMM    *)
  380.                                    (*        unless '/x' requested.   *)
  381.  
  382.    IF Use_EMM_For_Overlays THEN
  383.       Use_Emm_For_Overlays := EMMAvailable;
  384.  
  385.    IF ( NOT Use_EMM_For_Overlays ) THEN
  386.       BEGIN
  387.          MyGetOverlayArea( 0 , '', 32000 + 13500 );
  388.          MyGetOverlayArea( 1 , 'PT4TERM.CHN', 0 );
  389.       END;
  390.                                    (* Initialize PibTerm              *)
  391.    InitTerm;
  392.                                    (* Program finished flag           *)
  393.    PibTerm_Done := FALSE;
  394.                                    (* Begin Terminal Emulation        *)
  395.    REPEAT
  396.       Terminal_Emulations;
  397.    UNTIL ( PibTerm_Done );
  398.                                    (* Rewrite dialing directory       *)
  399.                                    (* if necessary                    *)
  400.    IF Any_Dialing_Changes THEN
  401.       IF MyLoadOverlay( 0 , PT4UTIL, 'PT4UTIL.CHN' ) THEN
  402.          Rewrite_Dialing_Directory;
  403.  
  404.                                    (* Clean up and terminate          *)
  405.    FiniTerm;
  406.  
  407.    Window( 1, 1, Max_Screen_Col, Max_Screen_Line );
  408.    Scroll( 1, Max_Screen_Line, 1, Max_Screen_Col, 0,
  409.            LightGray, Black );
  410.  
  411.    GoToXY( 1 , 1 );
  412.  
  413. END   (* PibTerm  *).
  414.